import {Config} from './config.js'
import {Token} from './token.js';
var token = new Token();
class Base{
  constructor()
  {
    'use strict'
    this.baseRestUrl = Config.restUrl;
  }
  /**
   * http 请求类, 当noRefech为true时，不做未授权重试机制
   */
  request(params,noRefech)
  {
    var that = this,
    url = this.baseRestUrl + params.url;
    if(!params.type)
    {
      params.type = 'get'
    }
    var token = my.getStorageSync({
          key: 'token',
        })
    my.request({
      url:url,
      method:params.type,
      data:params.data,
      headers:{
        'content-type': 'application/json',
        'token':token.data?token.data:''
      },
      success:function(res)
      {
        var code = res.status.toString();
        var startChar = code.charAt(0);
        if (startChar == '2') {
          params.sCallback && params.sCallback(res.data);
        } else {
          params.eCallback && params.eCallback(res.data);
        }
      },
      fail: function (err) {
       
      }
    })
  }

  _processError(err) {
    // console.log(err);
  }
  _refetch(param) {
    
  }
}

export {Base};